package com.mccken.practice.top100.Top_1$20.Top_20;

import com.mccken.practice.top100.ListNode;

/**
 * @program: mccken-collect
 * @description:
 * @author: mccken
 * @create: 2024-01-24 10:18
 **/
public class GetIntersectionNode {
	public ListNode getIntersectionNode(ListNode headA, ListNode headB) {

		if (headA == null || headB == null) {
			return null;
		}
		
		// 用pA指向headA
		ListNode pA = headA;
		ListNode pB = headB;
		
		while (pA != pB) {
			pA = pA == null ? headB : pA.next;
			pB = pB == null ? headB : pB.next;
		}
		
		return pA;
	}
	
	
}
